package com.weixing.mall.provider.controller.admin;


import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.api.model.enums.InOrOutEnum;
import com.weixing.mall.provider.model.dto.AddPointDto;
import com.weixing.mall.provider.model.query.MemberPointQuery;
import com.weixing.mall.provider.service.IMemberPointService;
import com.weixing.mall.provider.service.IMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 会员积分模块 前端控制器
 * </p>
 *
 * @author Small
 * @since 2020-04-13
 */
@Api(value = "后台:会员积分",tags = "后台:会员积分")
@RestController
@RequestMapping("/memberPoint")
public class MemberPointController extends BaseController {
    @Autowired
    private IMemberPointService memberPointService;
    @Autowired
    private IMemberService memberService;
    @ApiOperation("列表查询")
    @GetMapping("")
    public Result selectList(MemberPointQuery memberPointQuery){
        return ResultUtil.success(memberPointService.selectOfPage(initMpPage(),memberPointQuery));
    }



    @ApiOperation("赠送积分")
    @PostMapping("addPoint")
    public Result addPoint(@SysInfo SysAuth auth,@RequestBody @Validated AddPointDto addPointDto){
        return memberService.handlerPoint(addPointDto.getMemberId(), addPointDto.getPoint(),InOrOutEnum.IN.getValue(), addPointDto.getDesp(),auth.getUid())?ResultUtil.success():ResultUtil.error();
    }

}
